package com.ruoyi.quartz.task;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.text.CharSequenceUtil;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.constant.TaxiConstant;
import com.ruoyi.management.basics.service.ITCarService;
import com.ruoyi.management.basics.vo.GetCarNoCompanyIdVo;
import com.ruoyi.management.mock.service.ITNoticeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Set;


/**
 * 车牌号与公司对应关系存入redis
 * 
 * @author lss
 */
@Component("saveCarNoCompanyIdTask")
public class SaveCarNoCompanyIdTask
{
    @Autowired
    private ITCarService carService;
    @Autowired
    private RedisTemplate redisTemplate;

    /**
     * 车牌号与公司对应关系存入redis
     */
    @Transactional(rollbackFor = Exception.class)
    public void getCarNoCompanyId(){
        Set<String> keys = redisTemplate.keys(CharSequenceUtil.format(TaxiConstant.CAR_COMPANYID,"*"));
        redisTemplate.delete(keys);
        List<GetCarNoCompanyIdVo> list = carService.getCarNoCompanyId();
        for (GetCarNoCompanyIdVo vo : list) {
            String carNo = vo.getCarNo();
            carNo = CharSequenceUtil.sub(carNo, 1,carNo.length());
            String redisKey = CharSequenceUtil.format(TaxiConstant.CAR_COMPANYID,carNo);
            redisTemplate.opsForValue().set(redisKey, vo.getCompanyId());
        }
    }

}
